/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package processors;

import containers.TestsTaken;
import java.util.LinkedList;
import readers.QueryStringHandler;
import readers.UserReader;

/**
 * This creates a list of scores for the quizzes a student has taken
 * as the webcomponent uses a different processor this will only be
 * called by students, thus the naming
 * @author Chris
 */
public class processorQuizScores extends processor {
    private String _errMsg;
    processorQuizScores(String query) {
        super(query);
        _errMsg = "<quizScores></quizScores>";
    }
    
    @Override
    String process() {
        QueryStringHandler qsh = new QueryStringHandler(_queryString);
        String userName = qsh.getElement("userName");
        
        if(userName == null) {
            return _errMsg;
        }
        LinkedList<TestsTaken> taken = new LinkedList<TestsTaken>();

        UserReader.getTakenTests(userName, taken);

        String result = "<quizScores>";
        TestsTaken tt;
        while(!taken.isEmpty()) {
            tt = taken.getFirst();
            
            result += "<quiz><teacher>" + tt.teacher + "</teacher>" +
                    "<group>" + tt.group + "</group>" +
                    "<test>" + tt.test + "</group>" +
                    "<score>" + tt.score + "/score></quiz>";
            
            taken.removeLast();
        }
        result += "</quizScores>";
        
        return result;
    }
}
